package com.itheima.reggie.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.common.BaseContext;
import com.itheima.reggie.common.R;
import com.itheima.reggie.dto.OrdersDto;
import com.itheima.reggie.entity.Orders;
import com.itheima.reggie.entity.ShoppingCart;
import com.itheima.reggie.service.IOrdersService;
import com.itheima.reggie.service.IShoppingCartService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/order")
@Slf4j
public class OrdersController {

    @Autowired
    private IOrdersService ordersService;

    @PostMapping("/submit")
    public R submit(@RequestBody Orders orders) {

        log.info("submit");
        ordersService.submit(orders);

        return R.success("清空购物车成功");
    }

    @GetMapping("/userPage")
    public R userPage(Integer page ,Integer pageSize){
        IPage<Orders> pageInfo =new Page<>(page,pageSize);
        LambdaQueryWrapper<Orders> lqw = new LambdaQueryWrapper<>();
        lqw.eq(Orders::getUserId,BaseContext.getThreadLocal());
        ordersService.page(pageInfo,lqw);
        return R.success(pageInfo);
    }

    @GetMapping("/page")
    public R page(Integer page ,Integer pageSize){
        IPage<Orders> pageInfo =new Page<>(page,pageSize);
        ordersService.page(pageInfo,null);
        return R.success(pageInfo);
    }


}


